/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.contorller;

import com.apache.api.vo.ResultMsg;
import com.apache.portal.common.enums.InfoMethodEnum;
import com.apache.portal.common.util.PortalPubFactory;
import com.apache.tools.StrUtil;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * description:  收藏servlet
 */
@SuppressWarnings("serial")
public class FavoriteOrMqServlet extends BaseHttpServlet {

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     */
    protected void doInvoke(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String result = "";
        ResultMsg msg = null;
        Map<String, String> params = this.getParameterMap(request);
        String methodKey = request.getParameter("doCode");
        switch (InfoMethodEnum.getName(methodKey)) {
        case Fcount:
            long fcount = (Long) PortalPubFactory.getInstance().getPlugin("favorite")
                    .doInvoke(request, response, params);
            result = fcount + "";
            break;
        case Mcount:
            long mcount = (Long) PortalPubFactory.getInstance().getPlugin("favorite")
                    .doInvoke(request, response, params);
            result = mcount + "";
            break;
        }
        if (StrUtil.isNull(result)) {
            msg = (ResultMsg) PortalPubFactory.getInstance().getPlugin("favorite")
                    .doInvoke(request, response, params);
            if (null == msg) {
                msg = new ResultMsg("F", "操作失败");
            }
            result = JSONObject.fromObject(msg).toString();
        }
        outputJson(result, response);
    }

}
